package trip;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "TIME_TABLE",
	uniqueConstraints = @UniqueConstraint(columnNames={"trip_id", "stop_number"}))
public class Time_table {
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;
	
	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "trip_id") 
	private Trip trip;
	
	@Column(name = "stop_number", nullable = false)
	private Integer stop_number;

	@Column(name = "price", nullable = false)
	private Integer price;

	@Column(name = "arrival", nullable = false)
	Date arrival;
	
	@Column(name = "departure", nullable = false)
	Date departure;

	@Column(name = "vacant_seats", nullable = true)
	private Integer vacant_seats;

	//constructors
	public Time_table() {};
	
	public Time_table(long id, Trip trip, Integer stop_number, Integer price, Date arrival, Date departure, Integer vacant_seats) {
		this.id = id;
		this.trip = trip;
		this.stop_number = stop_number;
		this.price = price;
		this.arrival = arrival;
		this.departure = departure;
		this.vacant_seats = vacant_seats;
	}
	
	//id
	public long getId() {
		return id;
	}

	public Time_table setId(long id) {
		this.id = id;
		return this;
	}

	//trip
	public Trip getTrip() {
		return trip;
	}

	public Time_table setTrip(Trip trip) {
		this.trip = trip; 
		return this;
	}
	
	//stop_number
	public Integer getStop_number() {
		return stop_number;
	}

	public Time_table setStop_number(Integer stop_number) {
		this.stop_number = stop_number;
		return this;
	}

	//price
	public Integer getPrice() {
		return price;
	}

	public Time_table setPrice(Integer price) {
		this.price = price; 
		return this;
	}

	//arrival
	public Date getArrival() {
		return arrival;
	}

	public Time_table setArrival(Date arrival) {
		this.arrival = arrival;
		return this;
	}

	//departure
	public Date getDeparture() {
		return departure;
	}

	public Time_table setDeparture(Date departure) {
		this.departure = departure;
		return this;
	}

	//vacant_seats
	public Integer getVacantSeats() {
		return vacant_seats;
	}

	public Time_table setVacantSeats(Integer vacant_seats) {
		this.vacant_seats = vacant_seats;
		return this;
	}
	
	public boolean equals(Time_table tt) {
		if (tt == null)
			return false;
		if (this.id == tt.id && 
			this.trip.equals(tt.trip) &&
			this.stop_number == tt.stop_number &&
			this.price == tt.price &&
			this.arrival == tt.arrival &&
			this.departure == tt.departure &&
			this.vacant_seats == tt.vacant_seats)
			return true;
		else
			return false;
	}
}